<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>角色列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
      <!-- 添加角色 -->
      <el-row>
        <el-col>
          <el-button type="primary">添加角色</el-button>
        </el-col>
      </el-row>
      <!-- 角色列表区域 -->
      <el-table :data="roleList" border stripe>
        <!-- 展开 -->
        <el-table-column type="expand">
          <template v-slot="slotinfo">
            <el-row
            v-for="(item1, idx1) in slotinfo.row.children" :key="item1.id"
            :class="['bd-bottom', idx1 == 0 ? 'bd-top' : '', 'verticalCenter']"
            >
              <!-- 一级权限 -->
              <el-col :span="5">
                <el-tag closable>{{ item1.authName }}</el-tag>
                <i class="el-icon-caret-right"></i>
              </el-col>
              <!-- 二级权限 -->
              <el-col :span="19">
                <el-row
                 v-for="(item2, idx2) in item1.children" :key="item2.id"
                 :class="[idx2 == 0 ? '' : 'bd-top', 'verticalCenter']"
                >
                  <el-col>
                    <el-tag type="success" closable>{{ item2.authName }}</el-tag>
                  </el-col>
                </el-row>
              </el-col>
            </el-row>
          </template>
        </el-table-column>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="角色名称" prop="roleName"></el-table-column>
        <el-table-column label="角色描述" prop="roleDesc"></el-table-column>
        <el-table-column label="操作">
          <template v-slot="">
            <el-button type="primary" icon="el-icon-edit" size="mini">编辑</el-button>
            <el-button type="danger" icon="el-icon-delete" size="mini">删除</el-button>
            <el-button type="warning" icon="el-icon-setting" size="mini">分配权限</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { getInfo } from '@/utils/http'
export default {
  data () {
    return {
      roleList: []
    }
  },
  created () {
    this.getRoleList()
  },
  methods: {
    async getRoleList () {
      const { data: res } = await getInfo('roles')
      if (res.status !== '200') {
        return this.$message.error('查询角色列表失败!', res.status)
      }
      this.roleList = res.data
    }
    // async removeRight () {
    //   this.$messageBox.confirm('确定退出吗？').then(() => {
    //     this.$message.success('成功退出')
    //   }).catch(err => console.log(err))
    // }
  }
}
</script>

<style lang="less" scoped>
.el-tag {
  margin: 7px;
}
.bd-top {
  border-top: 1px solid #ccc;
}
.bd-bottom {
  border-bottom: 1px solid #ccc;
}
.verticalCenter {
  display: flex;
  align-items: center;
}
</style>
